/**
 * @file testtime.cpp
 * @author 张奕欣3190105655 (3190105655@zju.edun.cn)
 * @brief 
 * @version 0.1
 * @date 2022-10-27
 * 
 * @copyright Copyright (c) 2022
 * 
 */

#include "AvlTree.h"
#include <iostream>
#include <vector>
#include <windows.h>
#include <cstdlib>
#include <chrono>
#include <iomanip>
using namespace std;

    // Test program
int main( )
{
    AvlTree<int> t;
    vector<double> TimeWorst;
    vector<double> TimeAve;
    vector<float> timeN;
    vector<float> timeK;

    // K =5, test N
    for (int size = 10;size <=300000;size*=2)
    {
        int k1 = size/2;
        int k2 = size/2+5;
        t.makeEmpty();
        for (int i = 0; i<size;i++)
        {
            t.insert(i);
        }
        double run_time;
	    _LARGE_INTEGER time_start;	//开始时间
	    _LARGE_INTEGER time_over;	//结束时间
	    double dqFreq;		//计时器频率
	    LARGE_INTEGER f;	//计时器频率
	    QueryPerformanceFrequency(&f);
	    dqFreq=(double)f.QuadPart;
	    QueryPerformanceCounter(&time_start);	//计时开始
        t.printRange(k1,k2);
        QueryPerformanceCounter(&time_over);	//计时结束
	    run_time=1000000*(time_over.QuadPart-time_start.QuadPart)/dqFreq;
	    //乘以1000000把单位由秒化为微秒，精度为1000 000/（cpu主频）微秒
        timeN.push_back(run_time);
    }
    // N = 100,000, test K
    for (int i = 0; i<100000;i++)
    {
        t.insert(i);
    }
    for (int k = 5; k< 50000; k*=2)
    {
        int k1 = 3;
        int k2 = k1+k-1;
        double run_time;
	    _LARGE_INTEGER time_start;	//开始时间
	    _LARGE_INTEGER time_over;	//结束时间
	    double dqFreq;		//计时器频率
	    LARGE_INTEGER f;	//计时器频率
	    QueryPerformanceFrequency(&f);
	    dqFreq=(double)f.QuadPart;
	    QueryPerformanceCounter(&time_start);	//计时开始
        t.printRange(k1,k2);
        QueryPerformanceCounter(&time_over);	//计时结束
	    run_time=1000*(time_over.QuadPart-time_start.QuadPart)/dqFreq;
	    //乘以1000把单位由秒化为毫秒
        timeK.push_back(run_time);
    }
    cout << "test N" <<endl;
    for (int i=0;i<timeN.size();i++)
        cout<<timeN.at(i)<< "us" <<endl;

    cout << "test k" <<endl;
    for (int i=0;i<timeK.size();i++)
        cout<<timeK.at(i)<< "ms" <<endl;

    
}